<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->
<!--

/**
 * filename, brief description, date of creation, by whom
 * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
 * @link: http://HeuristScholar.org
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @package Heurist academic knowledge management system
 * @todo
 **/

-->
<html>
 <head>
  <link rel=stylesheet href="../../../common/css/global.css">
  <link rel=stylesheet href="../../../common/css/edit.css">


 </head>

 <body class="editTab">
  <script src="../../../common/js/utilsLoad.js"></script>
  <script src="../../../common/php/displayPreferences.php"></script>
	<div>
	    <h2>Workgroup tags &nbsp;&nbsp;</h2>
	    <span class="help prompt" style="font-size: 11px;">
	       These tags can only be added or removed by members of the workgroup.<br>
	       Use them to flag records for publication in website listings.
	    </span>
	</div>
	<div class="tagTable">
      <div style="width:270px; display:table-cell">
      <b>Available</b>
       <div class=wgtag-list><table border=0 cellspacing=0 cellpadding=0 width="260px"><tbody id=all-workgroup-tags></tbody></table></div>
       <div class="help"><span class=prompt>Double-click on a tag to add it to this record</span></div>
      </div>
       <div id=button-box style="display:table-cell; vertical-align:middle;">
        <div><input type=button value="&gt;" title="Add a tag" onMouseDown="HEURIST.wgTagEditor.addWgTag(window.selectedRow)" disabled id=add-button></div>
        <div>&nbsp;&nbsp;</div>
        <div><input type=button value="&lt;" title="Remove a tag" onMouseDown="HEURIST.wgTagEditor.removeWgTag(window.selectedRow)" disabled id=remove-button></div>
       </div>
      <div style="width:270px; display:table-cell">
      <b>Selected</b>
       <div class=wgtag-list><table border=0 cellspacing=0 cellpadding=0 width="260px"><tbody id=current-workgroup-tags></tbody></table></div>
       <div class="help"><span class=prompt>Double-click on a tag to remove it from this record</span></div>
      </div>
	  </div>
      <div id="admin-wgTags"><br><a href="#" onclick="{showEditWgTagsDialog(); return false;}"> Click here </a> to add/delete tags for workgroups (administrators only). </div>

<script>
	document.write('<form id=wgtag-form method=post jsonAction="'+top.HEURIST.basePath+'records/tags/updateRecordTagLinks.php" action="'+top.HEURIST.basePath+'records/tags/updateRecordTagLinks.php"></form>');
</script>
<script src="../../tags/usergroupTagEditorLibrary.js"></script>
<script>

function showEditWgTagsDialog(){

	var windowRef = document.parentWindow  ||  document.defaultView  ||  document._parentWindow;

	var database = (top.HEURIST.database.name || top.HEURIST.parameters.db);

	top.HEURIST.util.popupURL(windowRef, top.HEURIST.basePath + "admin/ugrps/editGroupTags.php?popup=yes"+(database ? "&db="+database : ""), { callback: function(tags) {
		if (tags){

			var _updateTags = function(context){

					if(!top.HEURIST.util.isnull(context)) {

						top.HEURIST.user.workgroupTags = context['workgroupTags'];
						top.HEURIST.user.workgroupTagOrder = context['workgroupTagOrder'];

						//recreate table
						HEURIST.wgTagEditor.reloadTags();
					}
			}

			var baseurl = top.HEURIST.basePath + "records/tags/reloadUsergroupTags.php";
			var callback = _updateTags;
			var params = "db="+database;
			top.HEURIST.util.getJsonData(baseurl, callback, params);
		}

	} });

	return false;
}

var removeButton = document.getElementById("remove-button");
var addButton = document.getElementById("add-button");

document.forms[0].heuristSubmit = function() {
	top.HEURIST.util.xhrFormSubmit(document.forms[0], function(json) {
		var vals = eval(json.responseText);
		if (vals) parent.HEURIST.edit.record.workgroupTags = vals;
		window.location.reload();
	});
};
var bibInput = document.createElement("input");
	bibInput.type = "hidden";
	bibInput.name = "recID";
	bibInput.value = top.HEURIST.edit.record.bibID;
document.getElementById("wgtag-form").appendChild(bibInput);


var currWgTagsElt = document.getElementById("current-workgroup-tags");
var allWgTagsElt = document.getElementById("all-workgroup-tags");
new HEURIST.wgTagEditor.WgTagEditor(currWgTagsElt, allWgTagsElt, addButton, removeButton);

</script>


 </body>
</html>
